﻿#ifndef __RM_H__
#define __RM_H__
//#include "Global.h"
#include "Texture.h"
#include "Surface.h"
//#include "Map.h"
#include "Sprite.h"
#include "Object.h"

#include "Utility.h"

#include <list>
#include <vector>
#include <fstream>
#include <sstream>
#include <map>
using namespace std;


/**--------------------------------------------------------
*Program/Project : GameMario
*Written by :
*Email :
*Created date : 7/10/2012
*Modified by :
*Modified date :
*Version : 1.0
*Description : Load va quan ly tai nguyen nhu am thanh, hinh anh,..
--------------------------------------------------------**/
enum ResourceID
{
	RESOURCE__GAMEPLAY_MAP,
	RESOURCE_MARIO,
};

//trang thai cac doi tuong
enum INFO_SCREEN
{
	INFO_MARIO,
	INFO_COIN,
	INFO_WORLD1,
	INFO_WORLD2,
	INFO_TIME,
	INFO_RESULT
};
enum SCORE_LIST
{
	SCORE,
	HEART,
	NUMBER_LIFE,
	TIME,
	WORLD1
};



enum ITEM_STATE
{
	IS_REMOVE,		//trang thai can xoa
	IS_IDLE,		//trang thai binh thuong
	IS_MOVING,		//item co the di chuyen
	IS_ACTIVING,	//kich hoat item hien len
	//IS_ATE,			//item bi mario an
	IS_FREE,		//trang thai tu do
	IS_READY,		//trang thai san sang
	IS_FLOWER,		//trang thai la hoa, khong phai nam
	IS_EXPLOSION	//trang thai no cua bullet
};

//State Brick
enum BLOCK_STATE
{
	BS_REMOVE,		//khi gach bi vo, can xoa
	BS_NORMAL,		//trang thai binh thuong
	BS_IDLE_2,
	BS_MOVEUP,		//gach bi nhay len 1 doan khi mario doi len
	BS_BREAKING,	//gach dang bi vo
	BS_BREAKED,		//gach da vo
	BS_ACTIVING,		//cho phep object hoat dong
	BS_NONE			//gach:21 chua 5 coin
};

enum ENEMY_STATE
{
	ES_REMOVE,
	ES_NORMAL,
	ES_ACTIVING,
	ES_FIGHT,				//Khi Red Dargon

	ES_PAUSE,				//Tam dung hoat dong.

	ES_MOVE_SHELL_RIGHT,
	ES_FALL,				//Khi Goomba hoặc Koopa bị rơi (chuẩn bị chết)
	ES_FALLBULLET,			//Khi Koopa bi bullet mario cham

	ES_DIED,
	ES_JUMP					//Trang thai Nhay cua con Red Dragon
};

enum MARIO_STATE
{
	MS_REMOVE,			//xoa mario
	MS_DIE,				//mario dang chet
	MS_NORMAL,			//binh thuong

	//MS_SMALLTOBIG,		//trang thai chuyen tu nho den lon
	//MS_BIGTOSMALL,		//trang thai chuyen tu lon den nho
	//MS_BIGTOBULLET,		//trang thai chuyen tu lon den bullet
	//MS_BULLETTOSMALL,	//trang thai chuyen tu bullet den nho

	MS_PROTECT,			//trang thai bao ve player sau khi bi mat mau
	MS_HASSTAR,			//trang thai mario da an sao

	//MS_CREPTPINE,		//mario chui vao cong(Pine)
	//MS_GOUPPINE,		//mario chui len cong(Pine)

	MS_BLOOD_LOOS,		//player bi mat mau
	MS_LIGHT			//player an cac items
};

//vu khi cua simon
enum AXE_VERSION
{
	WEAPON_NONE,
	WEAPON_AXE,
	WEAPON_DAGGER,
	WEAPON_HOLY_WATER,
	WEAPON_BOOMERANG
};


enum GAME_STATE
{
	GS_MENU,			//menu chinh
	GS_PLAYING,			//dang choi
	GS_LOAD,			//load man choi
	GS_SAVE,			//luu man choi
	GS_GAMEWIN,			//man hinh win
	GS_GAMEOVER,		//man hinh thua
	GS_NEXT_STAGE,		//man choi ke tiep
	GS_SUB_STAGE,		//man choi phu trong map chinh
	GS_REPLAY,			//choi lai man choi
	GS_RETURN_STAGE,	//tro lai man choi
	GS_ABOUT,			//thong tin ve game
	GS_CONFIRM,			//thong bao xac nhan 1 hanh dong
	GS_PAUSE			//trang thai tam dung game, de luu game
};


class ResourceMng
{
private:
	LPDIRECT3DDEVICE9 d3ddv;
	LPDIRECT3DSURFACE9 backBuffer;

	//load all resource
	ResourceMng(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 backBuffer);

	//unique instance, dam bao chi co 1 thuc the duy nhat nam giu cac tai nguyen
	static ResourceMng* _instance;

	//-------------------- RESOURCE ----------------------
	//List of surface
	vector<Surface*> surface_list;
	vector<Object*> obj_list;


	//List of Texture2
	vector<Texture*> texture_list;

	//map surface
	map<int, LPWSTR> map_surface;
	//map texture
	map<int, Texture*> map_texture;

public:
	//release all resource
	~ResourceMng(void);

	//get the unique instance, lay thuc the giu cac tai nguyen
	static ResourceMng* GetInst(LPDIRECT3DDEVICE9 d3ddv, LPDIRECT3DSURFACE9 backBuffer);

	//Sprite *GetSprite(ResourceID id);

	//get surface, texture
	Surface* GetSurface(LPWSTR fileName);
	Texture* GetTexture(LPWSTR fileName);



	//Map *GetMap(ResourceID id);

	//Load surface from file
	void LoadSurfaceFile(char* file_name);
	//Load texture from file
	void LoadTextureFile(LPDIRECT3DDEVICE9 d3ddv, char* file_name);

	map<int, LPWSTR> getMapSurface() { return map_surface; }
	map<int, Texture*> getMapTexture() { return map_texture; }

	void LoadTextureToList();
	void LoadSurfaceToList();
};

#endif